<?php
// +----------------------------------------------------------------------
// | 文件说明
// +----------------------------------------------------------------------
// | Copyright (c) 2015
// +----------------------------------------------------------------------
// | Author: baiping 125618036@qq.com http://www.webipcode.com
// +----------------------------------------------------------------------
// |2016-3-31 下午2:19:03
// +----------------------------------------------------------------------

class Tmsearchnew_model extends CI_Model{
	
	private $table_name = 'tmsearchnew';
	public function __construct(){
		parent::__construct();
	}
	/**
	 * 执行wher条件
	 * @param unknown_type $where
	 * @author Baip
	 */
	private function _where($where){
		if ( is_array( $where ) ){
			foreach ( $where as $key => $val ){
				if ( is_array( $val ) ){
					$this->db->where_in($key, $val);
					unset($where[$key]);
				}else{
					$this->db->where($key, $val);
				}
			}
		}
		return true;
	}
	
	/**
	 * 获取数据
	 * @param unknown_type $where
	 * @param unknown_type $field
	 * @param unknown_type $limit
	 * @param unknown_type $offset
	 * @param unknown_type $order
	 */
	public function getDataObj($where, $field="*", $limit=15, $offset=0,  $order="id DESC"){
		$this->_where($where);
		$this->db->select($field);
		$this->db->order_by($order);
		$this->db->limit($limit, $offset);
		$res = $this->db->get($this->table_name);
		echo $this->db->last_query().'<br>';
		return $res->result_array();
	} 
	
	/**
	 * 更新数据
	 * @param unknown_type $where
	 * @param unknown_type $data
	 */
	public function updateData($where, $data){
		$this->_where($where);
		$query = $this->db->update($this->table_name,$data);
		return $query;
	}
}